//
//  model.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2025/1/16.
//

import Foundation

class VoucherGoodsService {
    var voucher_id: String = "";
    var isAfterBuy: String = "";
    var goodsSaleType: Int = 1;
    var discount: String = "";
    var is_login: Int = 1
    var store_id: String = "4008"
    init(voucher_id: String) {
        self.voucher_id = voucher_id
    }
    func getVoucherGoods(params: [String: Any]) async throws -> RtResReturn<VoucherGoodsRes> {
        var bodyData:[String: Any] = [
            "voucher_id":self.voucher_id,
            "store_id":self.store_id,
        ]
        bodyData.merge(params) {(_, new) in new}
        do {
            let resData = try await NetworkManager.searchApi.post(url: "/voucherSearch/getVoucherGoods", data: bodyData, responseType: VoucherGoodsRes.self)
            return resData
        }catch {
            print("请求getVoucherGoods失败：\(error)")
            throw NetworkError.responseError
        }
    }
    // 满减提醒信息
    func getVoucherInfo(cart_type: Int) async throws -> RtResReturn<VoucherInfoRes> {
        let bodyData:[String: Any] = [
            "voucher_id":self.voucher_id,
            "isAfterBuy":self.isAfterBuy,
            "goodsSaleType":self.goodsSaleType,
            "discount":self.discount,
            "cart_type":cart_type,
            "is_login":self.is_login,
            "store_id":self.store_id
         ]
        do {
            let resData = try await NetworkManager.searchApi.post(url: "/voucherSearch/getVoucherInfo", data: bodyData, responseType: VoucherInfoRes.self)
            print("请求成功：\(resData)")
            return resData
        } catch {
            print("请求voucherInfo失败：\(error)")
            throw NetworkError.responseError
        }
    }
}
